//
//  SNSectionHeaderView.m
//  app
//
//  Created by 王少宁 on 15/8/20.
//  Copyright (c) 2015年 hdaren. All rights reserved.
//

#import "SNSectionHeaderView.h"

@implementation SNSectionHeaderView

- (instancetype)initWithShopModel:(SNShopBaseModel *)model
{
    if ([super init]) {
        [self createTitleViewWithShopModel:model];
    }
    return self;
}

- (void)createTitleViewWithShopModel:(SNShopBaseModel *)model
{
    if (!model.headerView) {
        return;
    }
    
    UIView * titleView = [[UIView alloc] initWithFrame:CGRectMake(0, kSectionHeaderViewH-kSectionTitleViewH, SCREEN_WIDTH, kSectionTitleViewH)];
    [self addSubview:titleView];
    
    UILabel * titleLineLable = [[UILabel alloc] initWithFrame:CGRectMake(5, 14, 5, 20)];
    titleLineLable.backgroundColor = [XCommon hexStringToColor:kTitleVerticalLineColor];
    [titleView addSubview:titleLineLable];
    
    UILabel * titleLabel = CREATE_WITH_FRAME_OF(UILabel, [titleLineLable.ufo fx:1.0 ox:10 fy:0], [titleLineLable.ubo ow:SCREEN_WIDTH - titleLineLable.ufo.xx - 20 -40 fh:1.0]);
    titleLabel.text = model.headerTitle;
    [titleView addSubview:titleLabel];
    
    if ([model isKindOfClass:[SNShopNoticesListModel class]]) { //最新公告,有可能有更多按钮

        
        
        UIButton * titleBtn = CREATE_WITH_FRAME_OF(UIButton, [titleLabel.ufo fx:1.0 fy:0],
                                                   [titleLabel.ubo ow:40 fh:1.0]);
        titleBtn.titleLabel.font = JKAppGlobleFontSmallTagText;
        [titleBtn setTitle:@"更多" forState:UIControlStateNormal];
        [titleBtn setTitleColor:[XCommon hexStringToColor:@"#737373"] forState:UIControlStateNormal];
        [titleBtn addTarget:self action:@selector(titleBtnClick) forControlEvents:UIControlEventTouchUpInside];
        [titleView addSubview:titleBtn];
    }
    
}

- (void)titleBtnClick
{
    if ([self.delegate respondsToSelector:@selector(moreBtnInHeaderViewClick)]) {
        [self.delegate performSelector:@selector(moreBtnInHeaderViewClick)];
    }
}

- (void)drawRect:(CGRect)rect {
    [self drawBackground:CGRectMake(0, 0, SCREEN_WIDTH, kSectionHeaderViewH-kSectionTitleViewH) color:[XCommon hexStringToColor:kColor_lightGray_cell]];
    [self drawBackground:CGRectMake(0, kSectionHeaderViewH-kSectionTitleViewH, SCREEN_WIDTH, kSectionTitleViewH) color:[UIColor whiteColor]];
    [self drawSeperatorLineLeft:0 right:0];
}

@end
